package com.surfacing.rcp.client.providers;

import java.text.SimpleDateFormat;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

import com.surfacing.rcp.client.util.CustomColors;
import com.surfacing.rcp.model.common.ITransportStatus;
import com.surfacing.rcp.model.entity.Journal;

public class JournalViewLabelProvider implements ITableLabelProvider,
		ITableColorProvider, ITransportStatus {
	// define the columns
	// SELECT j.protokollnummer, j.datum, j.name, tpz.transportziel,
	// j.alarmZeit, j.endZeit, j.created, j.changed, j.notfallort,
	// j.nachforderung, ea.einsatzart, ds.dienststelle, j.azubi,
	// CONCAT(n.firstName,''n.lastName) AS NFS, CONCAT(n.firstName,''n.lastName)
	// AS Arzt, j.naca, j.km \
	public static final int COLUMN_PROTOKOLLNUMMER = 0;
	public static final int COLUMN_DATUM = 1;
	public static final int COLUMN_PATIENT = 2;
	public static final int COLUMN_TPZ = 3;
	public static final int COLUMN_ALARMZEIT = 4;
	public static final int COLUMN_ENDZEIT = 5;
	public static final int COLUMN_CREATED = 6;
	public static final int COLUMN_CHANGED = 7;
	public static final int COLUMN_NOTFALLORT = 8;
	public static final int COLUMN_NACHFORDERUNG = 9;
	public static final int COLUMN_EINSATZART = 10;
	public static final int COLUMN_DIENSTSTELLE = 11;
	public static final int COLUMN_AZUBI = 12;
	public static final int COLUMN_NFS = 13;
	public static final int COLUMN_DCOTOR = 14;
	public static final int COLUMN_NACA = 15;
	public static final int COLUMN_KM = 16;

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		Journal journal = (Journal) element;
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		switch (columnIndex) {
		case COLUMN_PROTOKOLLNUMMER:
			return String.valueOf(journal.getProtokollnummer());
		case COLUMN_DATUM:
			return journal.getDatum().toString();
		case COLUMN_PATIENT:
			return journal.getName();
		case COLUMN_TPZ:
			return (journal.getTransportziel() != null) ? journal.getTransportziel().getTransportziel() : "";
		case COLUMN_ALARMZEIT:
			return sdf.format(journal.getAlarmZeit());
		case COLUMN_ENDZEIT:
			return sdf.format(journal.getEndZeit());
		case COLUMN_CREATED:
			sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
			return sdf.format(journal.getCreated());
		case COLUMN_CHANGED:
			sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
			return sdf.format(journal.getChanged());
		case COLUMN_NOTFALLORT:
			return journal.getNotfallort();
		case COLUMN_NACHFORDERUNG:
			return journal.getNachforderung().getAnforderung();
		case COLUMN_EINSATZART:
			return journal.getEinsatzart().getEinsatzart();
		case COLUMN_DIENSTSTELLE:
			return journal.getDienststelle().getDienststelle();
		case COLUMN_AZUBI:
			return journal.getAzubi();
		case COLUMN_NFS:
			return journal.getNfs().toString();
		case COLUMN_DCOTOR:
			return journal.getDoctor().toString();
		case COLUMN_NACA:
			return journal.getNaca().toString();
		case COLUMN_KM:
			return journal.getKm();
		}
		return null;
	}

	@Override
	public void addListener(ILabelProviderListener arg0) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public boolean isLabelProperty(Object arg0, String arg1) {
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener arg0) {
	}

	@Override
	public Color getBackground(Object element, int columnIndex) {
		Journal journal = (Journal) element;
		if (journal.getNaca().getNaca() == 4)
			return CustomColors.NACA_4;
		if (journal.getNaca().getNaca() == 5)
			return CustomColors.NACA_5;
		if (journal.getNaca().getNaca() == 6)
			return CustomColors.NACA_6;
		if (journal.getNaca().getNaca() == 7)
			return CustomColors.NACA_7;
		return null;
	}

	@Override
	public Color getForeground(Object element, int columnIndex) {
		return null;
	}
}